﻿using NetworkLib;
using System;
using System.Collections;

namespace NetworkLib.Tcp
{
    public class TcpNetworkStrategy : INetworkStrategy
    {
        public const string SERVER_IP = "server_ip";
        public const string SERVER_PORT = "server_port";

        public TcpNetworkStrategy()
        {
            this.ServerIP = string.Empty;
            this.Sync = true;
        }

        public IAcceptor CreateAcceptor()
        {
            return TcpAcceptor.Create(this.Sync, this.Port, 10);
        }

        public IConnector CreateConnector()
        {
            return new TcpConnector(true, this.ServerIP, this.Port);
        }

        public void Initialize(Hashtable param)
        {
            if (param.ContainsKey(SERVER_IP))
            {
                this.ServerIP = (string)param[SERVER_IP];
            }
            if (param.ContainsKey(SERVER_PORT))
            {
                this.Port = (int)param[SERVER_PORT];
            }
        }

        public int Port { get; set; }

        public string ServerIP { get; set; }

        public bool Sync { get; set; }
    }
}
